//
//  ViewController.m
//  拉勾7.17
//
//  Created by dllo on 16/7/17.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "ViewController.h"
#import "RegisterViewController.h"
#import "IdentifyPhoneNumberViewController.h"
#import "LookAroundTabBarViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
   
    // 背景imageView
    self.backgroundImageView = [UIImageView createBackgroundImageVIew];
    [self.view addSubview:_backgroundImageView];
    // 加一层毛玻璃
    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:1];
    UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
    effectview.frame = CGRectMake(0, 0, _backgroundImageView.frame.size.width, _backgroundImageView.frame.size.height);
    [_backgroundImageView addSubview:effectview];

    // 拉勾icon
    self.lagouIcon = [UIImageView createLaGouIcon];
    [self.view addSubview:_lagouIcon];
    
    // personTextField
    // 改变光标颜色(所有textField全改变)
    [[UITextField appearance] setTintColor:COLOR1];
    self.personTextfield = [CustomTextField createPersonTextFieldOnLoadPage];
    [self.view addSubview:_personTextfield];
    
    // passwordTextfield
    self.passwordTextfield = [CustomTextField createPasswordTextFieldOnLoadPage];
    [self.view addSubview:_passwordTextfield];
    
    // forgotPasswordButton;
    self.forgotPasswordButton = [UIButton createForgotPassword];
    [self.view addSubview:_forgotPasswordButton];
    
    // 忘记密码icon
    self.forgotIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_forgotPassword@%#3x.png"]];
    _forgotIcon.frame = CGRectMake(0, 0, 21, 21);
    _forgotIcon.alpha = 0.3;
    _forgotIcon.center = CGPointMake(WIDTH / 2 + 93 , 475);
    [self.view addSubview:_forgotIcon];
    
    // 登录login
    self.loginButton = [UIButton createLoginButton];
    [self.view addSubview:_loginButton];
    
    // 注册register
    self.registerButton = [UIButton createRegisterButton];
    [self.view addSubview:_registerButton];
    
    // 到处溜达button
    self.lookAroundButton = [UIButton createLookAroundButton];
    [self.view addSubview:_lookAroundButton];
    
    // textField 的处理
    
    [self dealWithTextField];
    // 忘记密码 的处理
    [self dealWithForgotPassword];
    // 注册拉钩 的处理
    [self dealWithRegister];
    // 忘记密码 的处理
    [self forgotPassword];
    // 随便逛逛 的处理
    [self lookAround];
    

    


}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];

}
- (void)jumpToTabBarVC {
    LookAroundTabBarViewController *tabBarVC = [[LookAroundTabBarViewController alloc] init];
    [self presentViewController:tabBarVC animated:NO completion:^{
        
        
    }];
}
- (void)lookAround {
    [self.lookAroundButton addTarget:self action:@selector(jumpToTabBarVC) forControlEvents:UIControlEventTouchUpInside];
}
- (void)jumpToIdentifyIphoneNumberViewController {
    IdentifyPhoneNumberViewController *identifyPhoneNumberVC = [[IdentifyPhoneNumberViewController alloc] init];
        CATransition *animation = [CATransition animation];
        animation.timingFunction = UIViewAnimationCurveEaseInOut;
        animation.duration = 0.3;
        animation.type = kCATransitionPush;
        animation.subtype = kCATransitionFromRight;
        [self.view.window.layer addAnimation:animation forKey:@"尼玛"];
    [self presentViewController:identifyPhoneNumberVC animated:NO completion:^{
        
        
        
    }];
//    [self.navigationController pushViewController:[IdentifyPhoneNumberViewController new] animated:YES];
    
}
- (void)forgotPassword {
    [self.forgotPasswordButton addTarget:self action:@selector(jumpToIdentifyIphoneNumberViewController) forControlEvents:UIControlEventTouchUpInside];
}
- (void)dealWithRegister {
    // 跳转注册页面
    [self.registerButton addTarget:self action:@selector(registerLagou) forControlEvents:UIControlEventTouchUpInside];
}
- (void)registerLagou {
    RegisterViewController *registerVC = [[RegisterViewController alloc] init];

    [self presentViewController:registerVC animated:NO completion:^{
        
        
    }];
//    [self.navigationController pushViewController:[RegisterViewController new] animated:YES];
}
- (void)dealWithForgotPassword {
    
}
- (void)dealWithTextField{
    // textField签协议
    self.personTextfield.delegate = self;
    self.passwordTextfield.delegate = self;
    // 回收键盘
    // 左边图标变颜色
    // 键盘上升动画
    // 键盘下降动画
    
    
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (self.lagouIcon.center.y != HEIGHT / 3) {
        [UIView animateWithDuration:0.6 animations:^{
            
//           self.lagouIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo_lagou@3x.png"]];
//           self.lagouIcon.center = CGPointMake(WIDTH / 2, HEIGHT / 3);
            self.personTextfield.center = CGPointMake(WIDTH / 2, HEIGHT / 2);
            self.passwordTextfield.center = CGPointMake(WIDTH / 2, HEIGHT / 2 + 53 + 1.5);
            self.forgotPasswordButton.frame = CGRectMake(WIDTH - 20 - 80, 450, 80, 50);
            self.loginButton.center = CGPointMake(WIDTH / 2, 520 + 20);
            self.forgotIcon.center = CGPointMake(WIDTH / 2 + 93 , 475);
            self.lagouIcon.frame = CGRectMake(163.833, 175.5, 86.3333, 139.667);
            
        }];
        
    }
    [textField resignFirstResponder];
    return YES;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if ([textField isEqual:self.personTextfield]) {
        [self.personTextfield.personImageView setImage:[UIImage imageNamed:@"icon_person1"]];
        [self.passwordTextfield.personImageView setImage:[UIImage imageNamed:@"icon_password"]];
    } else {
        [self.personTextfield.personImageView setImage:[UIImage imageNamed:@"icon_person"]];
        [self.passwordTextfield.personImageView setImage:[UIImage imageNamed:@"icon_password1"]];
    }
    // 键盘上升
    
    // 给定动画
    [UIView animateWithDuration:0.4 animations:^{
        self.personTextfield.center = CGPointMake(WIDTH / 2, 210);
        self.passwordTextfield.center = CGPointMake(WIDTH / 2, 210 + 54.5);
         self.lagouIcon.frame = CGRectMake(self.lagouIcon.frame.origin.x + self.lagouIcon.frame.size.width / 2, self.lagouIcon.frame.origin.y, 0, 0);
        self.forgotIcon.center = CGPointMake(WIDTH / 2 + 93, 210 + 54.5 + 60);
        self.forgotPasswordButton.center = CGPointMake(WIDTH - 20 - 40 , 210 + 54.5 + 60);
        self.loginButton.center = CGPointMake(WIDTH / 2, 210 + 54.5 + 120);
    }];
    
    
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
